package com.cherrish.demo;

/**
 * @author cherrish
 * @time 2019-03-05 10:02
 * @name TestBitCal
 * @desc:
 */
public class TestBitCal {
    public static void main(String[] args) {
        int a = 8;
        int b = 9;

        System.out.println(a^b);
        System.out.println(a&b);

        System.out.println((a&b) << 1);

        System.out.println(add(3, 4));
        System.out.println(factorial(11));
        System.out.println(count5(50));

    }

    public static int count(long n){
        int sum = 0;
        while (n > 0){
            sum += n/5;
            n/=5;
        }
        return sum;
    }

    public static int count5(long n){
        int sum = 0;
        while (n > 0){
            sum += 1;
            n/=25;
        }
        return sum;
    }

    public static long factorial(long a){
        if(a <= 2){
            return a;
        }
        return a * factorial(a - 1);
    }

    public static int add(int a, int b){
        int res = 0;
        int xor = a ^ b;
        int forworad = (a & b) << 1;
        if(forworad != 0){
            res = add(xor, forworad);
        }else {
            res = xor;
        }
        return res;
    }
}
